load("//:build_variables.bzl", "COPTS")
load("//tools/lint:linters.bzl", "clang_tidy_test")

package(
    default_visibility = ["//:android_cuttlefish"],
)

proto_library(
    name = "load_config_proto",
    srcs = ["load_config.proto"],
)

cc_proto_library(
    name = "load_config_cc_proto",
    deps = [":load_config_proto"],
)

cc_library(
    name = "configs_common",
    srcs = ["cf_configs_common.cpp"],
    hdrs = ["cf_configs_common.h"],
    deps = [
        ":load_config_cc_proto",
        "//cuttlefish/common/libs/utils:result",
        "//libbase",
        "@fmt",
        "@jsoncpp",
        "@protobuf",
    ],
)

clang_tidy_test(
    name = "configs_common_clang_tidy",
    srcs = [":configs_common"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "parser",
    srcs = [
        "cf_configs_instances.cpp",
        "cf_flags_validator.cpp",
        "cf_metrics_configs.cpp",
        "fetch_config_parser.cpp",
        "launch_cvd_parser.cpp",
        "launch_cvd_templates.cpp",
        "load_configs_parser.cpp",
        "selector_parser.cpp",
    ],
    hdrs = [
        "cf_configs_instances.h",
        "cf_flags_validator.h",
        "cf_metrics_configs.h",
        "fetch_config_parser.h",
        "launch_cvd_parser.h",
        "launch_cvd_templates.h",
        "load_configs_parser.h",
        "selector_parser.h",
    ],
    deps = [
        ":configs_common",
        ":load_config_cc_proto",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:flag_parser",
        "//cuttlefish/common/libs/utils:json",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/commands/assemble_cvd:flags_defaults",
        "//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
        "//cuttlefish/host/commands/cvd/fetch:host_tools_target",
        "//cuttlefish/host/commands/cvd/cli/parser/instance",
        "//cuttlefish/host/commands/cvd/utils",
        "//libbase",
        "@fmt",
        "@jsoncpp",
        "@protobuf//:json_util",
    ],
)

clang_tidy_test(
    name = "parser_clang_tidy",
    srcs = [":parser"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_test(
    name = "parser_test",
    srcs = [
        "configs_inheritance_test.cc",
        "flags_parser_test.cc",
        "metrics_configs_test.cc",
    ],
    copts = COPTS + [ "-Icuttlefish" ],
    deps = [
        "//cuttlefish/common/libs/utils:base64",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/common/libs/utils:result_matchers",
        "//cuttlefish/host/commands/assemble_cvd:launch_cvd_cc_proto",
        "//cuttlefish/host/commands/cvd/cli/parser",
        "//cuttlefish/host/commands/cvd/cli/parser:configs_common",
        "//cuttlefish/host/commands/cvd/cli/parser:test_common",
        "//libbase",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
        "@jsoncpp",
        "@protobuf",
        "@protobuf//:differencer",
    ],
)

clang_tidy_test(
    name = "parser_test_clang_tidy",
    srcs = [":parser_test"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "test_common",
    srcs = ["test_common.cc"],
    hdrs = ["test_common.h"],
    testonly = True,
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/commands/cvd/cli/parser",
        "@jsoncpp",
    ],
)

clang_tidy_test(
    name = "test_common_clang_tidy",
    srcs = [":test_common"],
    tags = ["clang_tidy", "clang-tidy"],
)
